Documentation > CMS Template API Library > Asset > CreateNewAsset(String,Asset,Asset,Dictionary[String,String],Boolean)

CreateNewAsset

Creates an asset in the given folder using a given model.

public CrownPeak.CMSAPI.Asset CreateNewAsset(String,Asset,Asset,Dictionary[String,String],Boolean)


Returns

The newly created asset. If model is a folder, it will create a folder. If model is a file it will create a file. If it fails an unloaded asset is returned, use IsLoaded to check

Parameters

NameDescriptionType
label The name of the asset. System.String
saveLocation The folder to save this asset. CrownPeak.CMSAPI.Asset
model The model for this asset. CrownPeak.CMSAPI.Asset
contentFields The content fields for this asset. Dictionary<String,String>
createModelChildren if set to true will also create the model's children if the model is of type Folder. System.Boolean

Code Example

C#

Sample:
Asset folderAsset = Asset.Load("/Site/myFolder");
// Use Asset.LoadDirect() to load the model because models are usually in "Draft".
Asset modelAsset = Asset.LoadDirect("/System/Models/MyModel");
// Some properties that will be added to the new assets content when we call CreateNewAsset
Dictionary<string, string> contentFields = new Dictionary<string, string>  { {"key1", "toy 1"},  {"key2", "toy 2"} };
//Create the asset.
Asset newAsset = Asset.CreateNewAsset("newname", folderAsset, modelAsset, contentFields);
if (!newAsset.IsLoaded)
Out.WriteLine("Create Failed: " + context.Error);

Connect with Crownpeak